import { Modal } from '@douyinfe/semi-ui';

/**
 * 通用确认对话框
 * @param {Object} options - 配置项
 * @param {string} options.title - 标题
 * @param {string} options.content - 内容
 * @param {Function} options.onOk - 确认回调
 * @param {Function} options.onCancel - 取消回调
 * @param {string} options.okText - 确认按钮文本
 * @param {string} options.cancelText - 取消按钮文本
 * @param {Object} options.style - 自定义样式
 */
export const showConfirmModal = ({
  title = '提示',
  content = '',
  onOk = () => {},
  onCancel = () => {},
  okText = '确定',
  cancelText = '取消',
  type = 'confirm', // confirm, info, error, warning, success
  width = 768,
  centered = true,
  icon = null,
  bodyStyle = {
    display: 'flex',
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'center',
  },
  okButtonProps = {
    style: { width: 220, height: 48, borderRadius: 8 },
  },
  cancelButtonProps = {
    style: { width: 220, height: 48, borderRadius: 8 },
  },
  className = 'custom-semi-modal-style',
  modalProps = {},
}) => {
  // 根据类型选择 Modal 方法
  const modalMethod = Modal[type] || Modal.confirm;

  return modalMethod({
    title,
    content,
    onOk,
    onCancel,
    okText,
    cancelText,
    width,
    centered,
    icon,
    bodyStyle,
    okButtonProps,
    cancelButtonProps,
    className,
    ...modalProps,
  });
};

/**
 * 信息提示对话框
 * @param {Object} options - 配置项
 */
export const showInfoModal = (options) => {
  return showConfirmModal({
    ...options,
    type: 'info',
    cancelText: undefined // 只显示一个按钮
  });
};

/**
 * 错误提示对话框
 * @param {Object} options - 配置项
 */
export const showErrorModal = (options) => {
  return showConfirmModal({
    ...options,
    type: 'error'
  });
};

/**
 * 警告提示对话框
 * @param {Object} options - 配置项
 */
export const showWarningModal = (options) => {
  return showConfirmModal({
    ...options,
    type: 'warning'
  });
};

/**
 * 成功提示对话框
 * @param {Object} options - 配置项
 */
export const showSuccessModal = (options) => {
  return showConfirmModal({
    ...options,
    type: 'success'
  });
};
